(ns read-print-map
 (:import (java.io BufferedReader FileReader))
 (:use ('clojure.contrib.duck-streams))
 (:use ('clojure.contrib.seq-utils)))

(def y-axis 0)

(def map-field {:status "empty" :g 0 :h 0 :f 0 :parent nil})

(def path-map (sorted-map [0 0] map-field))

;used to create starting map
(defn fill-path-map [path-map x y status]
  (assoc path-map [x y] (assoc map-field :status status)))

(defn create-matrix-row [line, y-axis]
  (def path-map (sorted-map [0 y-axis] map-field))
  (loop [x-axis 0 character (get line 0) pm path-map]
    (def path-map (fill-path-map
                    pm
                    x-axis
                    y-axis
                    (if(= character \#)
                      "notempty"
                      (if (= character \.)
                        "empty"
                        (str character)))))
    (if (<= x-axis (- (count line) 1)) ;condition
      (recur (inc x-axis) (get line (inc x-axis)) path-map)  ;true part
      pm;false part
      )
    )
  )

(defn create-matrix [lines]
  (loop [y-axis 0 pm path-map]
    (def one-row-map (create-matrix-row (get lines y-axis) y-axis))
    (def tmp-path-map (merge pm one-row-map))
    (if(<= y-axis (- (count lines) 1)) ;condition
      (recur (inc y-axis) tmp-path-map) ;then part
      pm ;else part
      )
    )
  )

(defn get-line-for-y-value [whole-map sequ y]
  (def line-str "")
  (loop [i 0 sq1 line-str]
    (let [tmp-vec (nth sequ i)]
      (if (= (peek tmp-vec) y);condition
        (def line-str (str sq1
                        (if (= (val (find (val (find whole-map tmp-vec)) :status)) "empty")
                          "."
                          (if (= (val (find (val (find whole-map tmp-vec)) :status)) "notempty")
                            "#"
                            (str (val (find (val (find whole-map tmp-vec)) :status)))
                            )
                          ) )
          )
        )
      (if (<= i (- (count sequ) 2))
        (recur (inc i) line-str);then
        sq1;else
        )
      )
    )
  )

;print whole sorted map
(defn print-whole-map [whole-map y-dimension]
  (loop [y 0]
    (def line (get-line-for-y-value whole-map (keys whole-map) y))
    (println line)
    (if (<= y y-dimension) ;condition
      (recur (inc y));then
      )
    )
  )